<?php
declare (strict_types = 1);

namespace App\Controller\Packet;

/**
 *
 */
class CodeMap
{
    public $clientMap = [
        1000 => 'CLIENT_VERSION',
        1001 => 'DISCONNECT',
        1002 => 'KEEP_ALIVE',
        1003 => 'NEW_ACCOUNT',
        1004 => 'CHANGE_PASSWORD',
        1005 => 'LOGIN',
        1006 => 'NEW_CHARACTER',
        1007 => 'DELETE_CHARACTER',
        1008 => 'START_GAME',
        1009 => 'LOG_OUT',
        1010 => 'TURN',
        1011 => 'WALK',
        1012 => 'RUN',
        1013 => 'CHAT',
        1014 => 'MOVE_ITEM',
        1015 => 'STORE_ITEM',
        1016 => 'TAKE_BACK_ITEM',
        1017 => 'MERGE_ITEM',
        1018 => 'EQUIP_ITEM',
        1019 => 'REMOVE_ITEM',
        1020 => 'REMOVE_SLOT_ITEM',
        1021 => 'SPLIT_ITEM',
        1022 => 'USE_ITEM',
        1023 => 'DROP_ITEM',
        1024 => 'DEPOSIT_REFINE_ITEM',
        1025 => 'RETRIEVE_REFINE_ITEM',
        1026 => 'REFINE_CANCEL',
        1027 => 'REFINE_ITEM',
        1028 => 'CHECK_REFINE',
        1029 => 'REPLACE_WED_RING',
        1030 => 'DEPOSIT_TRADE_ITEM',
        1031 => 'RETRIEVE_TRADE_ITEM',
        1032 => 'DROP_GOLD',
        1033 => 'PICK_UP',
        1034 => 'INSPECT',
        1035 => 'CHANGE_A_MODE',
        1036 => 'CHANGE_P_MODE',
        1037 => 'CHANGE_TRADE',
        1038 => 'ATTACK',
        1039 => 'RANGE_ATTACK',
        1040 => 'HARVEST',
        1041 => 'CALL_NPC',
        1042 => 'TALK_MONSTER_NPC',
        1043 => 'BUY_ITEM',
        1044 => 'SELL_ITEM',
        1045 => 'CRAFT_ITEM',
        1046 => 'REPAIR_ITEM',
        1047 => 'BUY_ITEM_BACK',
        1048 => 'S_REPAIR_ITEM',
        1049 => 'MAGIC_KEY',
        1050 => 'MAGIC',
        1051 => 'SWITCH_GROUP',
        1052 => 'ADD_MEMBER',
        1053 => 'DEL_MEMBER',
        1054 => 'GROUP_INVITE',
        1055 => 'TOWN_REVIVE',
        1056 => 'SPELL_TOGGLE',
        1057 => 'CONSIGN_ITEM',
        1058 => 'MARKET_SEARCH',
        1059 => 'MARKET_REFRESH',
        1060 => 'MARKET_PAGE',
        1061 => 'MARKET_BUY',
        1062 => 'MARKET_GET_BACK',
        1063 => 'REQUEST_USER_NAME',
        1064 => 'REQUEST_CHAT_ITEM',
        1065 => 'EDIT_GUILD_MEMBER',
        1066 => 'EDIT_GUILD_NOTICE',
        1067 => 'GUILD_INVITE',
        1068 => 'GUILD_NAME_RETURN',
        1069 => 'REQUEST_GUILD_INFO',
        1070 => 'GUILD_STORAGE_GOLD_CHANGE',
        1071 => 'GUILD_STORAGE_ITEM_CHANGE',
        1072 => 'GUILD_WAR_RETURN',
        1073 => 'MARRIAGE_REQUEST',
        1074 => 'MARRIAGE_REPLY',
        1075 => 'CHANGE_MARRIAGE',
        1076 => 'DIVORCE_REQUEST',
        1077 => 'DIVORCE_REPLY',
        1078 => 'ADD_MENTOR',
        1079 => 'MENTOR_REPLY',
        1080 => 'ALLOW_MENTOR',
        1081 => 'CANCEL_MENTOR',
        1082 => 'TRADE_REQUEST',
        1083 => 'TRADE_REPLY',
        1084 => 'TRADE_GOLD',
        1085 => 'TRADE_CONFIRM',
        1086 => 'TRADE_CANCEL',
        1087 => 'EQUIP_SLOT_ITEM',
        1088 => 'FISHING_CAST',
        1089 => 'FISHING_CHANGE_AUTOCAST',
        1090 => 'ACCEPT_QUEST',
        1091 => 'FINISH_QUEST',
        1092 => 'ABANDON_QUEST',
        1093 => 'SHARE_QUEST',
        1094 => 'ACCEPT_REINCARNATION',
        1095 => 'CANCEL_REINCARNATION',
        1096 => 'COMBINE_ITEM',
        1097 => 'SET_CONCENTRATION',
        1098 => 'AWAKENING_NEED_MATERIALS',
        1099 => 'AWAKENING_LOCKED_ITEM',
        1100 => 'AWAKENING',
        1101 => 'DISASSEMBLE_ITEM',
        1102 => 'DOWNGRADE_AWAKENING',
        1103 => 'RESET_ADDED_ITEM',
        1104 => 'SEND_MAIL',
        1105 => 'READ_MAIL',
        1106 => 'COLLECT_PARCEL',
        1107 => 'DELETE_MAIL',
        1108 => 'LOCK_MAIL',
        1109 => 'MAIL_LOCKED_ITEM',
        1110 => 'MAIL_COST',
        1111 => 'UPDATE_INTELLIGENT_CREATURE',
        1112 => 'INTELLIGENT_CREATURE_PICKUP',
        1113 => 'ADD_FRIEND',
        1114 => 'REMOVE_FRIEND',
        1115 => 'REFRESH_FRIENDS',
        1116 => 'ADD_MEMO',
        1117 => 'GUILD_BUFF_UPDATE',
        1118 => 'NPC_CONFIRM_INPUT',
        1119 => 'GAMESHOP_BUY',
        1120 => 'REPORT_ISSUE',
        1121 => 'GET_RANKING',
        1122 => 'OPENDOOR',
        1123 => 'GET_RENTED_ITEMS',
        1124 => 'ITEM_RENTAL_REQUEST',
        1125 => 'ITEM_RENTAL_FEE',
        1126 => 'ITEM_RENTAL_PERIOD',
        1127 => 'DEPOSIT_RENTAL_ITEM',
        1128 => 'RETRIEVE_RENTAL_ITEM',
        1129 => 'CANCEL_ITEM_RENTAL',
        1130 => 'ITEM_RENTAL_LOCK_FEE',
        1131 => 'ITEM_RENTAL_LOCK_ITEM',
        1132 => 'CONFIRM_ITEM_RENTAL',
    ];

    public $serverMap = [
        2000 => 'CONNECTED',
        2001 => 'CLIENT_VERSION',
        2002 => 'DISCONNECT',
        2003 => 'KEEP_ALIVE',
        2004 => 'NEW_ACCOUNT',
        2005 => 'CHANGE_PASSWORD',
        2006 => 'CHANGE_PASSWORD_BANNED',
        2007 => 'LOGIN',
        2008 => 'LOGIN_BANNED',
        2009 => 'LOGIN_SUCCESS',
        2010 => 'NEW_CHARACTER',
        2011 => 'NEW_CHARACTER_SUCCESS',
        2012 => 'DELETE_CHARACTER',
        2013 => 'DELETE_CHARACTER_SUCCESS',
        2014 => 'START_GAME',
        2015 => 'START_GAME_BANNED',
        2016 => 'START_GAME_DELAY',
        2017 => 'MAP_INFORMATION',
        2018 => 'USER_INFORMATION',
        2019 => 'USER_LOCATION',
        2020 => 'OBJECT_PLAYER',
        2021 => 'OBJECT_REMOVE',
        2022 => 'OBJECT_TURN',
        2023 => 'OBJECT_WALK',
        2024 => 'OBJECT_RUN',
        2025 => 'CHAT',
        2026 => 'OBJECT_CHAT',
        2027 => 'NEW_ITEM_INFO',
        2028 => 'MOVE_ITEM',
        2029 => 'EQUIP_ITEM',
        2030 => 'MERGE_ITEM',
        2031 => 'REMOVE_ITEM',
        2032 => 'REMOVE_SLOT_ITEM',
        2033 => 'TAKE_BACK_ITEM',
        2034 => 'STORE_ITEM',
        2035 => 'SPLIT_ITEM',
        2036 => 'SPLIT_ITEM1',
        2037 => 'DEPOSIT_REFINE_ITEM',
        2038 => 'RETRIEVE_REFINE_ITEM',
        2039 => 'REFINE_CANCEL',
        2040 => 'REFINE_ITEM',
        2041 => 'DEPOSIT_TRADE_ITEM',
        2042 => 'RETRIEVE_TRADE_ITEM',
        2043 => 'USE_ITEM',
        2044 => 'DROP_ITEM',
        2045 => 'PLAYER_UPDATE',
        2046 => 'PLAYER_INSPECT',
        2047 => 'LOG_OUT_SUCCESS',
        2048 => 'LOG_OUT_FAILED',
        2049 => 'TIME_OF_DAY',
        2050 => 'CHANGE_A_MODE',
        2051 => 'CHANGE_P_MODE',
        2052 => 'OBJECT_ITEM',
        2053 => 'OBJECT_GOLD',
        2054 => 'GAINED_ITEM',
        2055 => 'GAINED_GOLD',
        2056 => 'LOSE_GOLD',
        2057 => 'GAINED_CREDIT',
        2058 => 'LOSE_CREDIT',
        2059 => 'OBJECT_MONSTER',
        2060 => 'OBJECT_ATTACK',
        2061 => 'STRUCK',
        2062 => 'OBJECT_STRUCK',
        2063 => 'DAMAGE_INDICATOR',
        2064 => 'DURA_CHANGED',
        2065 => 'HEALTH_CHANGED',
        2066 => 'DELETE_ITEM',
        2067 => 'DEATH',
        2068 => 'OBJECT_DIED',
        2069 => 'COLOUR_CHANGED',
        2070 => 'OBJECT_COLOUR_CHANGED',
        2071 => 'OBJECT_GUILD_NAME_CHANGED',
        2072 => 'GAIN_EXPERIENCE',
        2073 => 'LEVEL_CHANGED',
        2074 => 'OBJECT_LEVELED',
        2075 => 'OBJECT_HARVEST',
        2076 => 'OBJECT_HARVESTED',
        2077 => 'OBJECT_NPC',
        2078 => 'NPC_RESPONSE',
        2079 => 'OBJECT_HIDE',
        2080 => 'OBJECT_SHOW',
        2081 => 'POISONED',
        2082 => 'OBJECT_POISONED',
        2083 => 'MAP_CHANGED',
        2084 => 'OBJECT_TELEPORT_OUT', //传送出去
        2085 => 'OBJECT_TELEPORT_IN', //传送进来
        2086 => 'TELEPORT_IN', //传送到
        2087 => 'NPC_GOODS',
        2088 => 'NPC_SELL',
        2089 => 'NPC_REPAIR',
        2090 => 'NPC_S_REPAIR',
        2091 => 'NPC_REFINE',
        2092 => 'NPC_CHECK_REFINE',
        2093 => 'NPC_COLLECT_REFINE',
        2094 => 'NPC_REPLACE_WED_RING',
        2095 => 'NPC_STORAGE',
        2096 => 'SELL_ITEM',
        2097 => 'CRAFT_ITEM',
        2098 => 'REPAIR_ITEM',
        2099 => 'ITEM_REPAIRED',
        2100 => 'NEW_MAGIC',
        2101 => 'REMOVE_MAGIC',
        2102 => 'MAGIC_LEVELED',
        2103 => 'MAGIC',
        2104 => 'MAGIC_DELAY',
        2105 => 'MAGIC_CAST',
        2106 => 'OBJECT_MAGIC',
        2107 => 'OBJECT_EFFECT',
        2108 => 'RANGE_ATTACK',
        2109 => 'PUSHED',
        2110 => 'OBJECT_PUSHED',
        2111 => 'OBJECT_NAME',
        2112 => 'USER_STORAGE',
        2113 => 'SWITCH_GROUP',
        2114 => 'DELETE_GROUP',
        2115 => 'DELETE_MEMBER',
        2116 => 'GROUP_INVITE',
        2117 => 'ADD_MEMBER',
        2118 => 'REVIVED',
        2119 => 'OBJECT_REVIVED',
        2120 => 'SPELL_TOGGLE',
        2121 => 'OBJECT_HEALTH',
        2122 => 'MAP_EFFECT',
        2123 => 'OBJECT_RANGE_ATTACK',
        2124 => 'ADD_BUFF',
        2125 => 'REMOVE_BUFF',
        2126 => 'OBJECT_HIDDEN',
        2127 => 'REFRESH_ITEM',
        2128 => 'OBJECT_SPELL',
        2129 => 'USER_DASH',
        2130 => 'OBJECT_DASH',
        2131 => 'USER_DASH_FAIL',
        2132 => 'OBJECT_DASH_FAIL',
        2133 => 'NPC_CONSIGN',
        2134 => 'NPC_MARKET',
        2135 => 'NPC_MARKET_PAGE',
        2136 => 'CONSIGN_ITEM',
        2137 => 'MARKET_FAIL',
        2138 => 'MARKET_SUCCESS',
        2139 => 'OBJECT_SIT_DOWN',
        2140 => 'IN_TRAP_ROCK',
        2141 => 'BASE_STATS_INFO',
        2142 => 'USER_NAME',
        2143 => 'CHAT_ITEM_STATS',
        2144 => 'GUILD_NOTICE_CHANGE',
        2145 => 'GUILD_MEMBER_CHANGE',
        2146 => 'GUILD_STATUS',
        2147 => 'GUILD_INVITE',
        2148 => 'GUILD_EXP_GAIN',
        2149 => 'GUILD_NAME_REQUEST',
        2150 => 'GUILD_STORAGE_GOLD_CHANGE',
        2151 => 'GUILD_STORAGE_ITEM_CHANGE',
        2152 => 'GUILD_STORAGE_LIST',
        2153 => 'GUILD_REQUEST_WAR',
        2154 => 'DEFAULT_NPC',
        2155 => 'NPC_UPDATE',
        2156 => 'NPC_IMAGE_UPDATE',
        2157 => 'MARRIAGE_REQUEST',
        2158 => 'DIVORCE_REQUEST',
        2159 => 'MENTOR_REQUEST',
        2160 => 'TRADE_REQUEST',
        2161 => 'TRADE_ACCEPT',
        2162 => 'TRADE_GOLD',
        2163 => 'TRADE_ITEM',
        2164 => 'TRADE_CONFIRM',
        2165 => 'TRADE_CANCEL',
        2166 => 'MOUNT_UPDATE',
        2167 => 'EQUIP_SLOT_ITEM',
        2168 => 'FISHING_UPDATE',
        2169 => 'CHANGE_QUEST',
        2170 => 'COMPLETE_QUEST',
        2171 => 'SHARE_QUEST',
        2172 => 'NEW_QUEST_INFO',
        2173 => 'GAINED_QUEST_ITEM',
        2174 => 'DELETE_QUEST_ITEM',
        2175 => 'CANCEL_REINCARNATION',
        2176 => 'REQUEST_REINCARNATION',
        2177 => 'USER_BACK_STEP',
        2178 => 'OBJECT_BACK_STEP',
        2179 => 'USER_DASH_ATTACK',
        2180 => 'OBJECT_DASH_ATTACK',
        2181 => 'USER_ATTACK_MOVE',
        2182 => 'COMBINE_ITEM',
        2183 => 'ITEM_UPGRADED',
        2184 => 'SET_CONCENTRATION',
        2185 => 'SET_OBJECT_CONCENTRATION',
        2186 => 'SET_ELEMENTAL',
        2187 => 'SET_OBJECT_ELEMENTAL',
        2188 => 'REMOVE_DELAYED_EXPLOSION',
        2189 => 'OBJECT_DECO',
        2190 => 'OBJECT_SNEAKING',
        2191 => 'OBJECT_LEVEL_EFFECTS',
        2192 => 'SET_BINDING_SHOT',
        2193 => 'SEND_OUTPUT_MESSAGE',
        2194 => 'NPC_AWAKENING',
        2195 => 'NPC_DISASSEMBLE',
        2196 => 'NPC_DOWNGRADE',
        2197 => 'NPC_RESET',
        2198 => 'AWAKENING_NEED_MATERIALS',
        2199 => 'AWAKENING_LOCKED_ITEM',
        2200 => 'AWAKENING',
        2201 => 'RECEIVE_MAIL',
        2202 => 'MAIL_LOCKED_ITEM',
        2203 => 'MAIL_SEND_REQUEST',
        2204 => 'MAIL_SENT',
        2205 => 'PARCEL_COLLECTED',
        2206 => 'MAIL_COST',
        2207 => 'RESIZE_INVENTORY',
        2208 => 'RESIZE_STORAGE',
        2209 => 'NEW_INTELLIGENT_CREATURE',
        2210 => 'UPDATE_INTELLIGENT_CREATURElIST',
        2211 => 'INTELLIGENT_CREATURE_ENABLE_RENAME',
        2212 => 'INTELLIGENT_CREATURE_PICKUP',
        2213 => 'NPC_PEARL_GOODS',
        2214 => 'TRANSFORM_UPDATE',
        2215 => 'FRIEND_UPDATE',
        2216 => 'LOVER_UPDATE',
        2217 => 'MENTOR_UPDATE',
        2218 => 'GUILD_BUFF_LIST',
        2219 => 'NPC_REQUEST_INPUT',
        2220 => 'GAME_SHOP_INFO',
        2221 => 'GAME_SHOP_STOCK',
        2222 => 'RANKINGS',
        2223 => 'OPENDOOR',
        2224 => 'GET_RENTED_ITEMS',
        2225 => 'ITEM_RENTAL_REQUEST',
        2226 => 'ITEM_RENTAL_FEE',
        2227 => 'ITEM_RENTAL_PERIOD',
        2228 => 'DEPOSIT_RENTAL_ITEM',
        2229 => 'RETRIEVE_RENTAL_ITEM',
        2230 => 'UPDATE_RENTAL_ITEM',
        2231 => 'CANCEL_ITEM_RENTAL',
        2232 => 'ITEM_RENTAL_LOCK',
        2233 => 'ITEM_RENTAL_PARTNER_LOCK',
        2234 => 'CAN_CONFIRM_ITEM_RENTAL',
        2235 => 'CONFIRM_ITEM_RENTAL',
        2236 => 'NEW_RECIPE_INFO',
        2237 => 'OPEN_BROWSER',
    ];

    public static $clinetPackMap;

    public static $serverPackMap;

    public function getCmdName(int $cmd): string
    {
        return $cmd < 2000 ? ($this->clientMap[$cmd] ?? '') : ($this->serverMap[$cmd] ?? '');
    }

    public function clinetPack()
    {
        if (!self::$clinetPackMap) {
            self::$clinetPackMap = array_flip($this->clientMap);
        }

        return self::$clinetPackMap;
    }

    public function serverPack()
    {
        if (!self::$serverPackMap) {
            self::$serverPackMap = array_flip($this->serverMap);
        }

        return self::$serverPackMap;
    }

    public function getServerPackCmd(string $cmdName): int
    {
        $packCmdList = $this->serverPack();
        return !empty($packCmdList[$cmdName]) ? $packCmdList[$cmdName] - 2000 : 0;
    }

    public function getClinetPackCmd(string $cmdName): int
    {
        $packCmdList = $this->clinetPack();
        return !empty($packCmdList[$cmdName]) ? $packCmdList[$cmdName] - 1000 : 0;
    }
}
